package com.yulang.springbootnetty.webscoket;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.IdleStateHandler;

public class WServerInit extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {

        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast(new HttpServerCodec());
        //大数据量写的时候使用
        pipeline.addLast(new ChunkedWriteHandler());
        //处理httpmessage进行聚合
        //几乎netty编程都要使用
        pipeline.addLast(new IdleStateHandler(60,60,60));
        pipeline.addLast(new HeartBeatHandler());
        pipeline.addLast(new HttpObjectAggregator(1024*64));


        //==============以上是协议支持

        // 服务器处理协议 会处理繁重的复杂的事，会处理握手动作，都是以frames进行传输的
        pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));

        pipeline.addLast(new MyHandler());


    }
}
